package interview.continer;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 *
 *  ArrayList带来的并发问题,解决方案
 *  1、使用Vector
 *  2、Collections.synchronizedList
 *  3、CopyOnWriteArrayList
 *
 * */
public class ListUnsafeDemo {

    public static void main(String[] args) {

        //List<String> list =  Collections.synchronizedList(new ArrayList<>());
        //List<String> list = new Vector<>();
       // List<String> list  = new CopyOnWriteArrayList();
        List<String> list = new ArrayList<>();
        for(int i=0;i<30;i++){
            new Thread(()->{
                list.add(UUID.randomUUID().toString().substring(0,8));
                System.out.println(Thread.currentThread().getName()+":"+list);
            },String.valueOf(i)).start();
        }
    }

    public static  void   add(List<String> list,String ret){
            list.add(ret);

    }
}
